<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
    xmlns:s="http://jboss.com/products/seam/taglib"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:rich="http://richfaces.org/rich"
    xmlns:a="http://richfaces.org/a4j"
    template="layout/template.xhtml">

<ui:define name="body">

	<h2 class="title"><a href="#">Gerenciar Perfis</a></h2><br/>
	
            <h:form id="perfilForm">
            
	           <h:panelGrid columns="1">
	            	<s:decorate template="/layout/edit.xhtml">
	            		<ui:define name="label">Nome:</ui:define>
	            		<h:inputText value="#{manterPerfilController.perfilEdicao.dscNome}" 
	            			maxlength="45"
	            			size="50"
	            			required="true"/>
	            	</s:decorate>
	            </h:panelGrid>
	            <br/>
	            <div class="actionButtons">
	            	<h:commandButton id="newPerm" value="Nova Permissão" 
				        		action="#{manterPerfilController.novaPermissao()}"/>
	            </div>
	            <br/>
	            <rich:dataTable value="#{manterPerfilController.listaPerfisFuncionalidade}"
	            	id="tabelaPermissoes"
	            	var="_perm">
	            	
	            	<rich:column style="text-align: center;">
	            		<f:facet name="header">
	            			<a:region>
		            			<h:selectBooleanCheckbox value="#{manterPerfilController.selecionadoTodosPerm}">
		            				<a:support event="onchange" action="#{manterPerfilController.selecionaTodosPerm()}"
		            					reRender="tabelaPermissoes"/>
		            			</h:selectBooleanCheckbox>
	            			</a:region>
						</f:facet>
	            		
	            		<h:selectBooleanCheckbox value="#{_perm.selecionado}" />
	            	</rich:column>
	            	
	            	<rich:column>
	            		<f:facet name="header">Funcionalidade</f:facet>
	            		<s:decorate template="/layout/editTable.xhtml">
		            		<h:selectOneMenu value="#{_perm.idFuncionalidade}"
		            			required="true">
		            			<f:selectItems value="#{manterPerfilController.listaFuncionalidades}"/>
		            		</h:selectOneMenu>
	            		</s:decorate>
	            	</rich:column>
	            	
	            	<rich:column style="text-align: center;">
	            		<f:facet name="header">Leitura</f:facet>
	            		<h:selectBooleanCheckbox value="#{_perm.leitura}" />
	            	</rich:column>
	            	
	            	<rich:column style="text-align: center;" >
	            		<f:facet name="header">Gravação</f:facet>
	            		<h:selectBooleanCheckbox value="#{_perm.gravacao}" />
	            	</rich:column>
	            	
	            	<rich:column style="text-align: center;">
	            		<f:facet name="header">Excluir</f:facet>
	            		<h:selectBooleanCheckbox value="#{_perm.exclusao}" />
	            	</rich:column>
	            	
	            	<rich:column style="text-align: center;">
	            		<f:facet name="header">Desconto</f:facet>
	            		<h:selectBooleanCheckbox value="#{_perm.desconto}" />
	            	</rich:column>
	            	
	            	<rich:column style="text-align: center;">
	            		<f:facet name="header">Controle total</f:facet>
            			<h:selectBooleanCheckbox value="#{_perm.flgControleTotal}">
            				<a:support event="onchange" action="#{manterPerfilController.selecionaTodasPermissoes(_perm)}"
            					reRender="tabelaPermissoes"/>
            			</h:selectBooleanCheckbox>
	            	</rich:column>
	            
	            </rich:dataTable>
	            <a:region>
	            	<table width="100%">
	            		<tr>
	            			<td width="25%" align="center">
					            <h:commandLink value="Excluir Permissão(ões)" action="#{manterPerfilController.excluirPermissao()}"
					            	onclick="#{rich:component('carregando')}.show()"
					            	reRender="tabelaPermissoes"/>
				            </td>
	            			<td width="25%" align="center">
					            <a:commandLink value="Inserir Todas Permissões" action="#{manterPerfilController.inserirTodasFuncionalidades()}"
					            	onclick="#{rich:component('carregando')}.show()"
				            		oncomplete="#{rich:component('carregando')}.hide()"
					            	reRender="tabelaPermissoes"/>
				            </td>
				            <td width="25%" align="center">
					            <a:commandLink value="Marcar todos" action="#{manterPerfilController.marcarDesmarcarTodos('true')}"
					            	onclick="#{rich:component('carregando')}.show()"
				            		oncomplete="#{rich:component('carregando')}.hide()"
					            	reRender="tabelaPermissoes"/>
				            </td>
				            <td width="25%" align="center">
					            <a:commandLink value="Desmarcar todos" action="#{manterPerfilController.marcarDesmarcarTodos('false')}"
					            	onclick="#{rich:component('carregando')}.show()"
				            		oncomplete="#{rich:component('carregando')}.hide()"
					            	reRender="tabelaPermissoes"/>
			            	</td>
		            	</tr>
	            	</table>
	            </a:region>
	            <br/>
	            <div class="actionButtons">
		        	<h:commandButton id="submit" value="Salvar" action="#{manterPerfilController.salvar}"
		            	onclick="javascript:if(!confirm('Tem certeza que deseja salvar?'))return false;"/>
		            	
		            <a:commandButton id="cancel" value="Cancelar" 
				        		action="#{manterPerfilController.cancelar}" 
				        		ajaxSingle="true"
				        		reRender="perfilForm"/>
		        </div>
				<br/>
				
			</h:form>

 </ui:define>
</ui:composition>
